package com.titan.demo.camel.utils.processor;

import org.apache.camel.Exchange;
import org.apache.camel.Expression;
import org.apache.camel.Processor;
import org.apache.camel.language.simple.SimpleLanguage;

import com.titan.core.utils.data.StringUtils;


/**
 * 打印对象类型，使用样例：
 * 	  .process(new PrintClassProcessor("${body}"))
 */
public class PrintClassProcessor implements Processor {
	private String exp = null;
	
	public PrintClassProcessor(String exp) {
		this.exp = exp;
	}
	
	public void process(Exchange exchange) throws Exception {
		if(StringUtils.isEmpty(exp)) {
			exp = "${body}";
		}
		Expression expression = SimpleLanguage.expression(exp);
		Object value = expression.evaluate(exchange, Object.class);
		if(value == null) {
			System.out.println(exp + "的对象class为：null");
		} else {
			System.out.println(exp + "的对象class为：" + value.getClass().getName());
		}
	}
}
